import { getUserBaseInfo } from "@/service/api/sp-common/user";
import { appGetStorage, appSetStorage } from "@/utils/storage";
import { USER_LOCATION_KEY } from "@/utils/location";

const state = {
  userInfo: null, //用户信息
  location: appGetStorage(USER_LOCATION_KEY), //位置信息
};

const mutations = {
  SET_USER_INFO: (state, val) => {
    state.userInfo = val;
  },
  SET_USER_LOCATION: (state, val) => {
    state.location = val;
  },
};

const actions = {
  async getUserBaseInfoAction({ commit }) {
    const res = await getUserBaseInfo();
    commit("SET_USER_INFO", res);
  },
  async setUserLocation({ commit }, data) {
    appSetStorage(USER_LOCATION_KEY, data);
    commit("SET_USER_LOCATION", data);
  },
};

const getters = {};

export default {
  namespaced: true,
  state,
  actions,
  getters,
  mutations,
};
